<?php
class ActionsController extends LiladsAppController {
	var $name = 'Actions';
	var $uses = array('Lilads.Action', 'Lilads.Campaign');
	var $helpers = array('Time');

	function admin_daily() {
		$params = $this->params['named'];
		
		if (empty($params['start'])) {
			$params['start'] = strftime('%Y-%m-%d', mktime(0, 0, 0, date("m"), 1, date("Y"))); 
		}
		
		if (empty($params['end'])) {
			$params['end'] = strftime('%Y-%m-%d', mktime(0, 0, 0, date("m")+1, 0, date("Y"))); 
		}
		
		if (empty($params['campaign_id']) || !is_numeric($params['campaign_id'])) {
			$this->redirect(array('controller'=>'campaigns', 'action'=>'stats'));
		}
		
		$this->set('campaign', $this->Campaign->read(null, $params['campaign_id']));
		$this->set('stats', $this->Action->getStats($params));
		$this->set('params', $params);
	}

	function admin_hourly() {
		$params = $this->params['named'];
		
		if (empty($params['date'])) {
			$params['date'] = strftime('%Y-%m-%d'); 
		}
		$params['start'] = $params['date'];
		$params['end'] = strftime('%Y-%m-%d', strtotime($params['start'])+24*60*60);
		
		if (empty($params['campaign_id']) || !is_numeric($params['campaign_id'])) {
			$this->redirect(array('controller'=>'campaings', 'action'=>'stats'));
		}
		
		$this->set('campaign', $this->Campaign->read(null, $params['campaign_id']));
		$this->set('stats', $this->Action->getStats($params, 13));
		
		// clear so these params doesn't get into url
		unset($params['start']); unset($params['end']);
		$this->set('params', $params);
	}
}
?>
